<template>
  <div class="rankData">
    <div class="heads">
      <div class="fh" @click="$router.go(-1)">
        <span class="iconfont icon-arrow-left-bold"></span> 返回
      </div>
      <div class="center">排行榜</div>
      <router-link class="shuJ" tag="div" to="/bookshelf"
        ><span class="iconfont icon-shujia"></span> 书架</router-link
      >
    </div>
    <van-loading size="24px" vertical v-if="!datas">加载中...</van-loading>
    <van-tabs
      v-model="active"
      @click="add"
      title-active-color="red"
      v-if="datas"
      line-width="0px"
      line-height="0px"
      background="transparent"
    >
      <van-tab :title="item.name" v-for="(item, index) in datas" :key="index">
        <van-tabs
          v-model="active2"
          @click="add"
          line-width="0px"
          line-height="0px"
          title-active-color="red"
          background="transparent"
        >
          <van-tab
            :title="i.name"
            v-for="(i, j) in item.subNavis"
            :key="j + '1'"
          >
            <div
              class="fist"
              v-for="item in list"
              :key="item.title"
              @click="goBook(item.id, item.title)"
            >
              <div class="img">
                <img :src="item.cover" alt="" width="100" height="100%" />
              </div>
              <div class="txt">
                <div class="title">{{ item.title }}</div>
                <div class="at-bq">{{ item.author }}/{{ item.category }}</div>
                <div class="center">
                  {{ item.content }}
                </div>
              </div>
            </div>
            <van-loading size="24px" vertical v-if="!list"
              >加载中...</van-loading
            >
          </van-tab>
        </van-tabs>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
import { getRankData, getRankList } from "../api/rankData";
export default {
  data() {
    return {
      active: 0,
      active2: 0,
      datas: null,
      list: null,
    };
  },
  methods: {
    add() {
      console.log(this.active, this.active2);
      let url = this.datas[this.active].subNavis[this.active2].naviInfos[0].url;
      getRankList(url).then((data) => {
        this.list = data.list;
      });
    },
    goBook(id, name) {
      console.log(id, name);
      this.$router.push({
        path: "/bookDetails",
        query: { id: id, name: name },
      });
    },
  },
  created() {
    getRankData().then((data) => {
      console.log(data);
      this.datas = data.data.list;
    });
    getRankList(
      "/store/rankList.json?rankType=26&uuid=ca03da7b64ca443ab25ec3b662fa91e2&all=0"
    ).then((data) => {
      this.list = data.list;
      console.log(this.list);
    });
  },
};
</script>

<style lang="less">
.rankData {
  overflow: hidden;
  .van-tab__text--ellipsis{
      // background-color: #c9483c;
      font-size: 14px;
      color: #fff;
      height: 19px;
      line-height: 19px;
      padding: 1px 5px;
      background-color: #bab6b3;
      text-align: center;
      border-radius: 4px;
      margin-right: 8px;
  }
  .van-tab--active {
    span {
      background-color: #c9483c;
    }
  }
  .heads {
    display: flex;
    justify-content: space-between;
    color: #fff;
    background-color: black;
    height: 50px;
    line-height: 50px;
    .center {
      font-size: 20px;
      span {
        font-size: 14px;
      }
    }
  }
  .fist {
    display: flex;
    margin: 10px;

    .img {
      width: 82px;
      height: 115px;
      margin-right: 30px;
      background-color: pink;
      flex-shrink: 0;
    }
    .txt {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .title {
        font-weight: normal;
        font-size: 16px;
        color: #3b352d;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        width: 80%;
      }
      .at-bq {
        font-size: 12px;
        color: #aba59a;
      }
      .center {
        display: -webkit-box;
        overflow: hidden;
        text-overflow: ellipsis;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        font-size: 14px;
        color: #807a73;
        overflow: hidden;
      }
    }
  }
}
</style>